package com.guyu.plugin.satoken.core;

import cn.dev33.satoken.stp.StpInterface;
import com.guyu.plugin.satoken.service.LoginUserService;
import com.guyu.plugin.satoken.service.SaTokenHelper;
import lombok.RequiredArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * sa-token 权限管理实现类
 *
 * @author Lion Li
 */
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final SaTokenHelper saTokenHelper;

    /**
     * 获取菜单权限列表
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        LoginUserService loginUserService = saTokenHelper.getLoginUserService(loginType);
        if (Objects.isNull(loginUserService)) {
            return new ArrayList<>();
        }
        return loginUserService.getPermissionList(loginId);
    }

    /**
     * 获取角色权限列表
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        LoginUserService loginUserService = saTokenHelper.getLoginUserService(loginType);
        if (Objects.isNull(loginUserService)) {
            return new ArrayList<>();
        }
        return loginUserService.getRoleList(loginId);
    }
}
